package development.group;

import state.GameForm;
import state.Graphics;
import state.GroupForm;
import state.component.Event;
import state.component.EventListener;
import state.component.MultiTab;
import state.util.Hashtable;
import development.Constants;
import development.DrawUtils;
import development.FrmNapXu;
import development.Global;
import development.app.Frm18plus;
import development.app.FrmMangXH;

public class FrmGroup18Plus extends GroupForm implements EventListener {
  private MultiTab multiTab;
  private static GameForm singleton;
  public static GameForm backForm;
  
  public static GameForm instance() {
    if (singleton == null) {
      singleton = new FrmGroup18Plus();
    }
    return singleton;
  }
  
  public void init(Hashtable parameters) {
    FrmNapXu frmNapXu = (FrmNapXu) FrmNapXu.instance();
    FrmMangXH frmMangXH = (FrmMangXH) FrmMangXH.instance();
    
    multiTab = new MultiTab(this, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
    multiTab.addTab("18+", Frm18plus.instance(), parameters);
    multiTab.addTab("Mạng XH", frmMangXH, parameters);
    multiTab.addTab("Nạp xu", frmNapXu, parameters);
    multiTab.setStyle(Constants.MULTI_TAB_STYLE);
    multiTab.selectTab(0);
    frmMangXH.getGridMenu().setBackTabWhenBeginRow(multiTab);
    frmMangXH.getGridMenu().setNextTabWhenEndRow(multiTab);
  }
  
  public static void setTab(int index) {
    FrmGroup18Plus frmGroup18Plus = (FrmGroup18Plus) FrmGroup18Plus.instance();
    MultiTab multiTab = frmGroup18Plus.getMultiTab();
    if (multiTab != null) {
      multiTab.selectTab(index);
    }
  }
  
  public MultiTab getMultiTab() {
    return multiTab;
  }
  
  public void draw(Graphics g) {
    DrawUtils.drawBackground(g);
  }
  
  public void onActionPerform(Event event) {
  }
  
  public void goBack() {
    Global.nextState(FrmGroupMenu.instance(), null);
  }
  
  public void destroy() {
    multiTab.detroy();
    multiTab = null;
    Frm18plus.instance().detroyAll();
    FrmMangXH.instance().detroyAll();
    FrmNapXu.instance().detroyAll();
  }
}
